package com.thundersoft.pickcolor.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.thundersoft.pickcolor.MainActivity;
import com.thundersoft.pickcolor.R;
import com.thundersoft.pickcolor.utils.ShareUtils;
import com.thundersoft.pickcolor.utils.StaticClass;
import com.thundersoft.pickcolor.utils.UtilTools;


/**
 * 闪屏页
 */
public class SplashActivity extends Activity {

    /**
     * 1.延时2000ms
     * 2.自定义字体
     * 3.Activity全屏主题
     * 4.根据登录状态进行相应的跳转
     */

    private TextView tv_splash;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case StaticClass.HANDLER_SPLASH:
                    if(ShareUtils.getBoolean(getApplicationContext(),"isLogin",false)){
                        startActivity(new Intent(SplashActivity.this,MainActivity.class));
                    }else {
                        startActivity(new Intent(SplashActivity.this,LoginActivity.class));
                    }
                    finish();
                    break;
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.NoTitle);
        setContentView(R.layout.activity_splash);
        initView();
    }

    // 初始化View
    private void initView() {
        // 延时2000ms
        handler.sendEmptyMessageDelayed(StaticClass.HANDLER_SPLASH,2000);
        tv_splash = findViewById(R.id.tv_splash);

        // 设置字体
        UtilTools.setFont(this,tv_splash);
    }

    //禁止返回键
    @Override
    public void onBackPressed() {
        // super.onBackPressed();
    }
}
